//
//  TabBarVC.swift
//  WBSwift
//
//  Created by maker on 11/8/16.
//  Copyright © 2016 maker. All rights reserved.
//

import UIKit

class TabBarVC: UITabBarController {

//    private lazy var pubulishBtn :UIButton = UIButton.creatBtn("tabbar_compose_icon_add", backImage: "tabbar_compose_button")
    fileprivate lazy var pubulishBtn :UIButton = UIButton(image: "tabbar_compose_icon_add", backImage: "tabbar_compose_button")
    override func viewDidLoad() {
        setupPublishBtn()
    }
    
}

//MARK:==========设置 UI==========
extension TabBarVC{
    //1.添加发布按钮
    func setupPublishBtn() {
        tabBar.addSubview(pubulishBtn)
        pubulishBtn.center = CGPoint(x: tabBar.center.x, y: tabBar.frame.size.height*0.5)
        
        /*
         Selector 的构建有两种方式 1)#selector(TabBarVC.publishBtnClick)
                                2)"方法名称"
         */
        pubulishBtn .addTarget(self, action: #selector(TabBarVC.publishBtnClick), for: .touchUpInside)
    }
    
    //2.调整 baritem 的布局
    func layoutItems() {
        for i in 0..<tabBar.items!.count{
            let item = tabBar.items![i]
            // i == 2 让按钮不可点击
            if i == 2 {
                item.isEnabled = false
                continue
            }
            //设置图片
//            item.selectedImage = UIImage(named: imageArray[i]+"_highlighted")
        }
    }
}

//MARK:==========事件监听==========
extension TabBarVC{
    
    /*
     private 变成私有的.但是不会添加到方法列表中.故会出现错误
     @objc  用@objc 修饰后用 OC 的方式.就会被添加到方法列表中去
     */
    @objc fileprivate func publishBtnClick() {
        let publish = PublishVC()
        let pubNav = UINavigationController(rootViewController: publish)
        present(pubNav, animated: true, completion: nil)
    }
}














